<%@ include file="/WEB-INF/pages/common/taglibs.jsp" %>
<%@ include file="/WEB-INF/pages/common/checkpermission.jsp" %>
<script type="text/javascript">
    var subWin=null;
    function searchRecord() {
        var currentForm = document.forms["searchForm"];
        var dateFrom = currentForm.elements["searchTO.dateFrom"];
        var dateTo = currentForm.elements["searchTO.dateTo"];

        if(!isEmpty(currentForm.elements["searchTO.recordYear"].value)){
            if(!validateForm_int(currentForm.elements["searchTO.recordYear"])){
            alert('<s:text name="label.year.error"/>');
            return;
            }
            if(parseInt(currentForm.elements["searchTO.recordYear"].value)<1900 ||parseInt(currentForm.elements["searchTO.recordYear"].value)>2050){
                alert('<s:text name="label.year.error"/>');
                return;
            }    
        }
        if (!validateForm_date(dateFrom)) {
            alert('<s:text name="label.fromdate.error"/>');
            return;
        }

        if (!validateForm_date(dateTo)) {
             alert('<s:text name="label.enddate.error"/>');
            return;
        }

		if(!isEmpty(dateFrom.value) && !isEmpty(dateTo.value)){
		    if (compare2Dates(dateFrom.value, dateTo.value) == 1) {
            	alert('<s:text name="label.compare.date.error"/>'); 
            	return;
        	}
		}
        currentForm.elements["searchTO.recordName"].value = currentForm.elements["searchTO.recordName"].value.trim();
        currentForm.elements["searchTO.recordType"].value = currentForm.elements["searchTO.recordType"].value.trim();
        currentForm.target = "_self";
        currentForm.action="search.action";
        currentForm.submit();
    }
    <s:if test='#attr.user.userRole=="O"'>
    function addRecord() {
        var currentForm = document.forms["searchForm"];
        currentForm.target = "_self";
        currentForm.action="viewAdd.action";
        currentForm.submit();
    }
    </s:if>
    function updateRecord(recordName) {
        var currentForm = document.forms["searchForm"];
        currentForm.elements["erecordModel.selectId"].value = recordName;
        currentForm.target = "_self";
        currentForm.action="view.action";
        currentForm.submit();
    }

    <s:if test='#attr.user.userRole=="O"'>
    function deleteRecord() {
        if (!atLeastOneRecordChecked('searchFormDiv')) {
            alert('<s:text name="label.select.atleast.one.record"/>');
        }else{
            var currentForm = document.forms["searchForm"];
            subWin=openNewWindow("about:blank", 150, 500, null, 1, null, null, null, null, "popWindow");
            currentForm.target = "popWindow";
            currentForm.action= "preDelete.action";
            currentForm.submit();
        }

    }

    function submitDelete(){
        if (subWin != null && subWin.open) subWin.close();
        if (window.confirm('<s:text name="label.confirm.delete"/>')) {
            var currentForm = document.forms["searchForm"];
            currentForm.target = "_self";
            currentForm.action="delete.action";
            currentForm.submit();
        }
    }
    </s:if>

</script>

<div id='searchFormDiv'>
<s:form name="searchForm" action="" >
    <s:hidden name="erecordModel.selectId" value="" />
    <s:hidden id="erecordModel.deletePassword" name="erecordModel.deletePassword" value="" />
    <table align="center" cellpadding="0" cellspacing="0" class="body_content full_width">
        <tr>
            <td align="left" valign="bottom" class="main_page_content_icon" width="4%">
                <img src='<c:url value="/images/body-icon_check.gif"/>' width="29" height="44">
            </td>
            <td valign="bottom" class="page_title_bg" width="96%">
                <span class="page_title">
                    <s:text name="label.search.erecord"/>
                </span>
            </td>
        </tr>
        <tr>
            <td class="subcontent" colspan="2">&nbsp;</td>
        </tr>
    </table>

    <table border="0" align="center" cellpadding="0" cellspacing="0" class="body_content full_width bordered">
        <tr class="even">
            <td class="form_label_padded" width="10%" nowrap><s:text name='label.name.erecord'/></td>
            <td class="form_label_padded" width="2%">:</td>
            <td class="txtData" align="left" width="38%">
                <s:textfield name="searchTO.recordName" />
            </td>

            <td class="form_label_padded" width="10%" nowrap><s:text name='label.type.erecord'/></td>
            <td class="form_label_padded" width="2%">:</td>
            <td class="txtData" align="left" width="38%">
            <s:select list="typeList" name="searchTO.recordType" listKey="value" listValue="label" headerKey="" headerValue=""/>
            </td>
        </tr>
        <tr class="odd">
            <td class="form_label_padded" width="10%" nowrap><s:text name='label.year'/></td>
            <td class="form_label_padded" width="2%">:</td>
            <td class="txtData" align="left" width="38%">
                <s:textfield name="searchTO.recordYear" />
            </td>

            <td class="form_label_padded" width="10%" nowrap><s:text name='label.ref.no'/></td>
            <td class="form_label_padded" width="2%">:</td>
            <td class="txtData" align="left" width="38%">
             <s:textfield name="searchTO.refNo" />
            </td>
        </tr>
        <tr class="even">
            <td class="form_label_padded" width="10%" nowrap><s:text name='label.source'/></td>
            <td class="form_label_padded" width="2%">:</td>
            <td class="txtData" align="left" width="38%">
                <s:textfield name="searchTO.source" />
            </td>
            <td class="form_label_padded" width="10%" nowrap><s:text name='label.appellee'/></td>
            <td class="form_label_padded" width="2%">:</td>
            <td class="txtData" align="left" width="38%">
             <s:textfield name="searchTO.appellee" />
            </td>
        </tr>
        <tr class="odd">
            <td class="form_label_padded" width="10%" nowrap><s:text name='label.undertaker'/></td>
            <td class="form_label_padded" width="2%">:</td>
            <td class="txtData" align="left" width="38%">
                <s:textfield name="searchTO.undertaker" />
            </td>
            <td class="form_label_padded" width="10%" nowrap><s:text name='label.caseresaon'/></td>
            <td class="form_label_padded" width="2%">:</td>
            <td class="txtData" align="left" width="38%">
             <s:textfield name="searchTO.caseReason" />
            </td>
        </tr>

        <tr class="odd">
            <td class="form_label_padded" width="10%" nowrap><s:text name='label.search.startdate'/></td>
            <td class="form_label_padded" width="2%">:</td>
            <td class="txtData" align="left">
            <cl:date name="searchTO.dateFrom"/>(<s:text name='label.date.format'/>)
            </td>
            <td class="form_label_padded" width="10%" nowrap><s:text name='label.search.enddate'/></td>
            <td class="form_label_padded" width="2%">:</td>
            <td class="txtData" align="left">
            <cl:date name="searchTO.dateTo"/>(<s:text name='label.date.format'/>)
            </td>
        </tr>                
        <tr class="even">
            <td class="txtData" colspan="6">
                <input type="button" class="button" value="<s:text name='label.search'/>" onclick="searchRecord();">
                <s:if test='#attr.user.userRole=="O"'>
                <input type="button" class="button" value="<s:text name='label.add'/>" onclick="addRecord();">
                <input type="button" class="button" value="<s:text name='label.delete'/>" onclick="deleteRecord();">
                </s:if>
            </td>
        </tr>

        <tr class="odd">
            <td colspan="6">
                <display:table name="helper" form="searchForm" uid="row" action="search.action">
                    <display:column titleKey="label.record.no" width="5%">
                        <s:property value="%{#attr.row_rowNum+(helper.pageNumber-1)*helper.objectsPerPage}" />
                    </display:column>
                    <display:column width="4%">
                        <s:checkbox name="resultList[%{#attr.row_rowNum-1}].selectId"
                            fieldValue="%{#attr.row.recordId}" />
                    </display:column>

                    <display:column titleKey="label.name.erecord"  sortable="true" sortProperty="RECORD_NAME" width="13%">
                        <a href="javascript:updateRecord('<s:property value="%{#attr.row.recordId}"/>')">
                        <s:property value="%{#attr.row.recordName}" /> </a>
                    </display:column>
                    <display:column titleKey="label.type.erecord"  sortable="true" sortProperty="RECORD_TYPE" width="13%">
                      <s:if test='#attr.row.recordType=="W"'>
                          <s:text name='label.wenshu.erecord'/>
                      </s:if>
                      <s:if test='#attr.row.recordType=="S"'>
                          <s:text name='label.susong.erecord'/>
                      </s:if>
                    </display:column>
                    <display:column titleKey="label.year"  sortable="true" sortProperty="RECORD_YEAR" width="13%">
                        <s:property value="%{#attr.row.year}" />
                    </display:column>
                    <display:column titleKey="label.ref.no"  sortable="true" sortProperty="RECORD_REF_NO" width="13%">
                        <s:property value="%{#attr.row.refNo}" />
                    </display:column>
                    <display:column titleKey="label.appellee"  sortable="true" sortProperty="APPELLEE" width="13%">
                        <s:property value="%{#attr.row.appellee}" />
                    </display:column>
                    <display:column titleKey="label.undertaker"  sortable="true" sortProperty="UNDERTAKER" width="13%">
                        <s:property value="%{#attr.row.undertaker}" />
                    </display:column>
                    <display:column titleKey="label.casedate"  sortable="true" sortProperty="CASE_DATE" width="13%">
                        <s:property value="%{#attr.row.caseDate}" />
                    </display:column>
                </display:table>
            </td>
        </tr>

    </table>
</s:form></div>
